package thread.threadexecutor;

import java.util.concurrent.*;

public class ThreadPool {

  public static void main(String[] args) {

    ExecutorService executorService = Executors.newCachedThreadPool();

    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 2,
            10L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(2));

    // 先启动 coresize ，
    // coresize 满了，这个时候加入队列
    // 队列满了，启动 maxPoolcoreSize
    for (int i = 1; i < 10; i++) {

      final int a = i;
      Future<?> submit = threadPoolExecutor.submit(new Runnable() {
        @Override
        public void run() {
          try {
            System.out.println(a);
            Thread.sleep(1000000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      });
      System.out.println(threadPoolExecutor);
    }

  }

}
